#!/bin/sh

function nukeFiles() {
    if [[ -e "$1" ]]; then
        if [[ -f "$1" ]]; then
            rm -v "$1"
        else
            rm -vr "$1"
        fi
    fi
}

function createFolder() {
	if [[ ! -e "$1" ]]; then
		mkdir -pv "$1"
	fi
	chmod 777 "$1"
}

log_dir="$HOME"/Library/"Application Support"/mySIMBL/logs
createFolder "$log_dir"
exec &>"$log_dir"/removeSIMBL.log
 
cleanupFiles=(
"/Library/Application Support/SIMBL"
"/Library/LaunchAgents/net.culater.SIMBL.Agent.plist"
"/Library/ScriptingAdditions/SIMBL.osax"
"/Library/ScriptingAdditions/EasySIMBL.osax"
"/System/Library/ScriptingAdditions/SIMBL.osax"
"/System/Library/LaunchAgents/net.culater.SIMBL.Agent.plist"
"$HOME/Library/ScriptingAdditions/SIMBL.osax"
"$HOME/Library/ScriptingAdditions/EasySIMBL.osax"
)

launchctl unload /Library/LaunchAgents/net.culater.SIMBL.Agent.plist
killall SIMBLAgent

echo "Removing files"

for i in "${cleanupFiles[@]}"; do
    echo Removing: "$i"
    nukeFiles "$i"
done

echo "Done"
